from rest_framework import serializers
from system.models import Demo
from rest_framework.serializers import ModelSerializer
from utils.viewset import CustomModelViewSet


class DemoSerializer(ModelSerializer):
    def validate_age(self,value):
        if value < 10:
            raise serializers.ValidationError(detail='<10')
        return value
    class Meta:
        model = Demo
        fields = "__all__"
        read_only_fields = ["id"]
        
class DemoViewSet(CustomModelViewSet):
    queryset = Demo.objects.all()
    serializer_class = DemoSerializer
    filter_fields = ["age", "name"]
    search_fields = ["age", "name"]